package tech.summerly.weather.util

import android.arch.lifecycle.Lifecycle
import android.arch.lifecycle.LifecycleObserver
import android.arch.lifecycle.OnLifecycleEvent
import com.amap.api.maps2d.MapView
import com.amap.api.maps2d.model.LatLng


fun Position.toLatLng(): LatLng {
    return LatLng(latitude, longitude)
}


fun MapView.observeLifecycle(lifecycle: Lifecycle) {
    lifecycle.addObserver(object : LifecycleObserver {

        @OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
        fun create() {
            onCreate(null)
        }

        @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
        fun resume() {
            onResume()
        }

        @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
        fun pause() {
            onPause()
        }

        @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
        fun destroy() {
            onDestroy()
        }
    })
}